#!bin/bash



if [ -n "$1" ] ; then
  data_date=$1
else
  data_date=`date -d "-1 days" +%F`
fi


DIM_GL_SJB_SQL="
DROP TABLE gd2_tmp_hive.dim_gl_sjb;
CREATE TABLE gd2_tmp_hive.dim_gl_sjb
AS
SELECT
    p.product_name,
    t.source_type,
    sw.search_word,
    ps.price_strength,
    s.sales_amount,
    t.source_uv,
    s.pay_buyer_count
FROM gd2_tmp_hive.ods_product p
         LEFT JOIN gd2_tmp_hive.fact_traffic_source t
                   ON p.product_id = t.product_id
                       AND p.dt = t.dt
         LEFT JOIN gd2_tmp_hive.fact_search_word sw
                   ON p.product_id = sw.product_id
                       AND p.dt = sw.dt
         LEFT JOIN gd2_tmp_hive.fact_price_strength ps
                   ON p.product_id = ps.product_id
                       AND p.dt = ps.dt
         LEFT JOIN gd2_tmp_hive.fact_product_sales s
                   ON p.product_id = s.product_id
                       AND p.dt = s.dt
WHERE p.dt = '2025-07-30'
ORDER BY s.sales_amount DESC;
"

/opt/module/spark/bin/beeline -u jdbc:hive2://node101:10001 -n bwie -p 123456 -e "${DIM_GL_SJB_SQL}"